
var r = {};
var search = "?id=4564&name=654";
search = search.substring(1);

var params = search.split('&')

console.log(params);

for (var i = 0; i < params.length; i++) {
  var ele = params[i];
  console.log(ele);
  var e1 = ele.split('=');
  console.log(e1);
  r[e1[0]] = e1[1] 
  
  // 如果有中文
  r[e1[0]] = decodeURIComponent(e1[1]) 
}

console.log(r);

function getQuery(params) {
  var query = location.search.substring(1);
  var params 
}


/**
 * https://segmentfault.com/a/1190000009554010
 */
function urlArgs() {
  var args = {};
  var query = location.search.substring(1);
  var pairs = query.split("&");
  for (var i = 0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf("=");
    if (pos == -1) {
      continue;
    }
    var name = pairs[i].substring(0, pos);
    console.log(name);
    var value = pairs[i].substring(pos + 1);
    args[name] = value;
  }
  return args;
}